<?php
class Search_Model_Seleki extends Search_Model_Base
{

	/**
	* 駅名一覧データ取得
	*
	* @access	public
	* @param	array
	* @return	void
	*/
	public function getEkiData($params)
	{
        $db_params = array();
        $sql = $this->generateEkiSql($params,$db_params);
        return $this->dbGetList($sql,$db_params);
    }

	/**
	* 駅名一覧データ取得（リクエスト用）
	*
	* @access	public
	* @param	array
	* @return	void
	*/
	public function getRequestEkiData($params)
	{
        $db_params = array();
        $sql = $this->generateEkiSql($params,$db_params,false);
        return $this->dbGetList($sql,$db_params);
    }

	/**
	* 静的URLから駅名一覧データ取得
	*
	* @access	public
	* @param	array
	* @return	void
	*/
	public function getEkiDataFromRailCd(&$params)
	{
        $db_params = array();
        // 沿線を一番多く持つ都道府県を取得
        $sql = $this->generateMaxRailCntSql($params,$db_params);
        $max_prefcd_data = $this->dbGetData($sql,$db_params);

        // TODO
        // 都道府県が複数とれた場合、どういった方法で単一の都道府県を選択するか
        // とりあえず、配列一番目のデータを格納

		// 都道府県コード返還
		return $max_prefcd_data['M04_TODOUFUKEN_CD'];
    }

	/**
	* 静的URLから駅名一覧データ取得
	*
	* @access	public
	* @param	array
	* @return	void
	*/
	public function getPrefCdByEkiCd($params)
	{
        $db_params = array();
        // 沿線を一番多く持つ都道府県を取得
        $sql = $this->generatePrefCdByStCdSql($params,$db_params);
        $prefcd_data = $this->dbGetList($sql,$db_params);
        $pref_data = array();
        foreach($prefcd_data as $key => $val){
        	$pref_data[$val['M03_EKI_CD']] = $val['M03_TODOUFUKEN_CD'];
        }

        return $pref_data;
    }

	/**
	* 駅コードから駅名取得
	*/
	public function getStNameByStCd($params)
    {
        $db_params = array();
        $sql = $this->generateStNameByStCdSql($params, $db_params);
        return $this->dbGetList($sql, $db_params);
    }

   /**
	* 駅名一覧データを表示用に変換
	*
	* @access	public
	* @param	array ※参照渡し
	* @return	void
	*/
	public function convertEkiData(&$data)
	{
		$data['Mapping'] = array();        
		$transfer = array();//乗り換える配列変数
		
		foreach ($data['seleki'] as $stationData)
		{
			$ensenCd = $stationData['ENSEN_CD'];
            $renrakuEnsenCd = $stationData['RENRAKU_ENSEN_CD'];
            
			// 沿線が異なる場合
			if (array_key_exists($ensenCd, $data['Mapping']) == false)
			{
				$data['Mapping'][$ensenCd]['ENSEN_NAME'] = $stationData['ENSEN_NAME'];
				$data['Mapping'][$ensenCd][] = array();
			}

			$data['Mapping'][$ensenCd]['EKI_DATA'][] = array(
			'EKI_NAME'			=> $stationData['EKI_NAME'],
			'EKI_CD'			=> $stationData['EKI_CD'],
			'REC_CNT'			=> $stationData['REC_CNT'],
			'TODOUFUKEN_CD'		=> $stationData['TODOUFUKEN_CD'],
			'PrefName'			=> Apm_Config_Search::$TODOUFUKEN_NAME_CODE_LIST[$stationData['TODOUFUKEN_CD']],		
			'EXPRESS_KBN'		=> $stationData['EXPRESS_KBN'],
			'RENRAKU_ENSEN_CD'         => ($renrakuEnsenCd != '' ? true : false),
			'RENRAKU_ENSEN_LIST'		=> str_replace(',', '-', $stationData['RENRAKU_ENSEN_LIST']),
			'RENRAKU_ENSEN_COUNT'		=> sizeof(explode(',', $stationData['RENRAKU_ENSEN_LIST']))
			);
			
			//乗り換える沿線CDを配列に入れる
			if($renrakuEnsenCd != '' && !in_array($renrakuEnsenCd, $transfer)){
			    $transfer[] = $renrakuEnsenCd;			    
			}
		}
		//$dataに放置する
		$data['TRANSFER_CD'] = implode(',', $transfer);
	}

    /**
     * 駅名データ検索用SQL文の取得
     *
     * 駅名一覧データ検索用SQL文の取得を行う
     * @access	public
     * @param	array
     * @param	array
     * @return	string 駅名データ検索用SQL
     */
    public function generateEkiSql($params,&$db_params,$existFlg=true)
    {

		//バインド変数のセット		
		// データ区分
		if(!empty($params['SrhKbn']) && $params['SrhKbn'] == Apm_Config_Search::SRHKBN_SYATAKU){
			$db_params['dataKubun'] = 2;
		}else{
			$db_params['dataKubun'] = 0;
		}	
	
		$sql = "SELECT ";
		if ($existFlg) {
			$sql .= "     T2.ENSEN_HEYA_CNT AS ENSEN_HEYA_CNT ";
			$sql .= "    ,T1.EKI_HEYA_CNT AS REC_CNT ";
		} else {
			$sql .= "     -1 AS ENSEN_HEYA_CNT ";
			$sql .= "    ,-1 AS REC_CNT";
		}
		$sql .= "        ,T1.ENSEN_CD AS ENSEN_CD";
		$sql .= "        ,T1.EKI_CD AS EKI_CD";
		$sql .= "        ,to_single_byte(T1.ENSEN_NAME) AS ENSEN_NAME";
		$sql .= "        ,T1.ENSEN_KANA AS ENSEN_KANA";
		$sql .= "        ,T1.EXPRESS_KBN AS EXPRESS_KBN";
		$sql .= "        ,T1.EKI_CD AS SORT";
		$sql .= "        ,CASE";
// 		$sql .= "            WHEN T1.EKI_NAME = '＊＊＊' THEN T3.TODOUFUKEN || to_single_byte(T1.ENSEN_NAME)";
		$sql .= "            WHEN T1.EKI_NAME = '＊＊＊' THEN to_single_byte(T1.ENSEN_NAME)";
		$sql .= "            ELSE to_single_byte(T1.EKI_NAME)";
		$sql .= "         END AS EKI_NAME";
		$sql .= "        ,T1.TODOUFUKEN_CD AS TODOUFUKEN_CD";
		$sql .= "        ,T1.RENRAKU_ENSEN_CD AS RENRAKU_ENSEN_CD";
		$sql .= "        ,T1.M03_RENRAKU_ENSEN_LIST AS RENRAKU_ENSEN_LIST"; //関連沿線一覧
		$sql .= "    FROM";
		$sql .= "        (";
		$sql .= "            SELECT";
		$sql .= "                     NVL(T54.EKI_HEYA_CNT, 0) AS EKI_HEYA_CNT";
		$sql .= "                    ,M03.M03_TODOUFUKEN_CD AS TODOUFUKEN_CD";
		$sql .= "                    ,M03.M03_ENSEN_CD AS ENSEN_CD";
		$sql .= "                    ,M03.M03_EKI_CD AS EKI_CD";
		$sql .= "                    ,M03.M02_ENSEN_NAME AS ENSEN_NAME";
		$sql .= "                    ,M03.M03_EKI_NAME AS EKI_NAME";
		$sql .= "                    ,M03.M02_ENSEN_KANA AS ENSEN_KANA";
		$sql .= "                    ,M03.M03_EXPRESS_KBN AS EXPRESS_KBN";
		$sql .= "                    ,M03.M03_RENRAKU_ENSEN_CD AS RENRAKU_ENSEN_CD";
		$sql .= "                    ,M03.M03_RENRAKU_ENSEN_LIST AS M03_RENRAKU_ENSEN_LIST"; //関連沿線一覧
		$sql .= "                FROM";
		$sql .= "                    (";
		$sql .= "                        SELECT";
		$sql .= "                                 SUM(T54_EKI_CNT) AS EKI_HEYA_CNT";
		$sql .= "                                ,T54_EKI_CD";
		$sql .= "                            FROM";
		$sql .= "                                T54EKI_SUM";
		$sql .= "                            WHERE";
// 		$sql .= "								T54_TODOUFUKEN_CD IN ". Apm_SqlUtil::generateWhereIn("PrefCD1",$params['PrefCd'],$db_params);		
// 		//$sql .=                                  $this->createWhere("T54_TODOUFUKEN_CD",$params['PrefCd']);
// 		$sql .= "                                AND";
		$sql .= "								T54_ENSEN_CD IN ". Apm_SqlUtil::generateWhereIn("RailCD1",$params['RailCd'],$db_params);		
		//$sql .=                                  $this->createWhere("T54_ENSEN_CD",$params['RailCd']);
		$sql .= "                            	AND T54_DATA_KUBUN =  :dataKubun";		
		$sql .= "                            GROUP BY";
		$sql .= "                                T54_EKI_CD";
		$sql .= "                    ) T54";
		$sql .= "                    ,(";
		$sql .= "                        SELECT";
		$sql .= "                                 M03_EKI_CD";
		$sql .= "                                ,M03_ENSEN_CD";
		$sql .= "                                ,M03_TODOUFUKEN_CD";
		$sql .= "                                ,M02_ENSEN_NAME";
		$sql .= "                                ,nvl(M03_EKI_ALIAS,M03_EKI_NAME) M03_EKI_NAME";
		$sql .= "                                ,M02_ENSEN_KANA";
		$sql .= "                                ,M03_TODOUFUKEN";
		$sql .= "                                ,M03_EXPRESS_KBN";
		$sql .= "                                ,M03_RENRAKU_ENSEN_CD";
		$sql .= "                                ,(CASE WHEN M03_RENRAKU_ENSEN_CD IS NOT NULL THEN (SELECT CAST(WM_CONCAT(DISTINCT SUB.M03_ENSEN_CD) AS VARCHAR(1024)) FROM M03EKI SUB WHERE SUB.M03_RENRAKU_ENSEN_CD = M03EKI.M03_RENRAKU_ENSEN_CD) ELSE '' END) AS M03_RENRAKU_ENSEN_LIST"; //関連沿線一覧
		$sql .= "                            FROM";
		$sql .= "                                M02ENSEN";
		$sql .= "                                ,M03EKI";
		$sql .= "                            WHERE";
// 		$sql .= "								M03_TODOUFUKEN_CD IN ". Apm_SqlUtil::generateWhereIn("PrefCD2",$params['PrefCd'],$db_params);				
// 		//$sql .=                                  $this->createWhere("M03_TODOUFUKEN_CD",$params['PrefCd']);
// 		$sql .= "                                AND";
		$sql .= "								M03_ENSEN_CD IN ". Apm_SqlUtil::generateWhereIn("RailCD2",$params['RailCd'],$db_params);				
		//$sql .=                                  $this->createWhere("M03_ENSEN_CD",$params['RailCd']);
		$sql .= "                                AND M02_ENSEN_CD = M03_ENSEN_CD";
		$sql .= "                    ) M03";
		$sql .= "                WHERE";
		$sql .= "                    T54.T54_EKI_CD(+) = M03.M03_EKI_CD";
		$sql .= "        ) T1";
		$sql .= "        ,(";
		$sql .= "            SELECT";
		$sql .= "                     SUM(T57_ENSEN_CNT) AS ENSEN_HEYA_CNT";
		$sql .= "                    ,T57_ENSEN_CD AS ENSEN_CD";
		$sql .= "                FROM";
		$sql .= "                    T57ENSEN_SUM";
		$sql .= "                WHERE";
// 		$sql .= "					T57_TODOUFUKEN_CD IN ". Apm_SqlUtil::generateWhereIn("PrefCD3",$params['PrefCd'],$db_params);					
// 		//$sql .=                      $this->createWhere("T57_TODOUFUKEN_CD",$params['PrefCd']);
// 		$sql .= "                    AND";
		$sql .= "					T57_ENSEN_CD IN ". Apm_SqlUtil::generateWhereIn("RailCD3",$params['RailCd'],$db_params);				
		//$sql .=                      $this->createWhere("T57_ENSEN_CD",$params['RailCd']);
		$sql .= "                    AND T57_DATA_KUBUN = :dataKubun";	
		$sql .= "                GROUP BY";
		$sql .= "                    T57_ENSEN_CD";
		$sql .= "        ) T2";
// 		$sql .= "        ,(";
// 		$sql .= "            SELECT";
// 		$sql .= "                     M43_TODOUFUKEN_CD AS TODOUFUKEN_CD";
// 		$sql .= "                    ,M43_TODOUFUKEN AS TODOUFUKEN";
// 		$sql .= "                FROM";
// 		$sql .= "                    M43TODOUFUKEN";
// 		$sql .= "                WHERE";
// 		$sql .= "					M43_TODOUFUKEN_CD IN ". Apm_SqlUtil::generateWhereIn("PrefCD4",$params['PrefCd'],$db_params);			
// 		//$sql .=                      $this->createWhere("M43_TODOUFUKEN_CD",$params['PrefCd']);
// 		$sql .= "        ) T3";
		$sql .= "    WHERE";
		$sql .= "        T1.ENSEN_CD = T2.ENSEN_CD(+)";
// 		$sql .= "        AND T1.TODOUFUKEN_CD = T3.TODOUFUKEN_CD";
		//if ($existFlg) {
			// 物件の存在する駅のみ取得
			//$sql .= "    AND T1.EKI_HEYA_CNT > 0";
		//}
		if(isset($params['listPage']) && $params['listPage']){
		    $sql .= "    ORDER BY";
    		$sql .= "        SORT ASC";
		}
		else {
    		$sql .= "    ORDER BY";
    		$sql .= "        ENSEN_KANA ASC";
    		$sql .= "        ,SORT ASC";
		}
		
        return $sql;
    }

    /**
	* !!!!!使用していない＆使用できない（SQL間違い）なので注意!!!!!
	* 駅名データ検索用SQL文の取得(OEM)
	*
	* 駅名データ検索用SQL文の取得を行う(OEM)
	* @access	public
	* @param	array
	* @param	array
	* @return
	*/
	public function generateOemSql($params,$db_params)
	{
		// OEMコードが8桁の場合,店舗検索
		// その他の場合、法人用検索
		$oemWhere = "";
		if(mb_strlen($params['OemCd'][0]) == 8){
			$oemWhere = $this->createWhere("T03_TENPO_CD",$params['OemCd']);
			$oemWhere .=" AND (M05_OEM = 2 OR M05_OEM = 5)";
		}else{
			$oemWhere = $this->createWhere("M05_HOUZIN_CD",$params['OemCd']);
			$oemWhere .=" AND (M05_OEM = 1 OR M05_OEM = 5)";
		}

		$sql = "SELECT";
		$sql .= "        T.ENSEN_REC_COUNT AS ENSEN_HEYA_CNT";
		$sql .= "        ,NVL(T.EKI_REC_COUNT, 0) AS REC_CNT";
		$sql .= "        ,T.M03_ENSEN_CD AS ENSEN_CD";
		$sql .= "        ,T.M03_EKI_CD AS EKI_CD";
		$sql .= "        ,to_single_byte(A.M02_ENSEN_NAME) AS ENSEN_NAME";
		$sql .= "        ,A.M02_ENSEN_KANA AS ENSEN_KANA";
		$sql .= "        ,T.M03_EKI_CD AS SORT";
		$sql .= "        ,CASE";
		$sql .= "            WHEN T.M03_EKI_NAME = '＊＊＊' THEN B.M43_TODOUFUKEN || to_single_byte(A.M02_ENSEN_NAME)";
		$sql .= "            ELSE to_single_byte(T.M03_EKI_NAME)";
		$sql .= "        END AS EKI_NAME";
		$sql .= "    FROM";
		$sql .= "        M02ENSEN A";
		$sql .= "        ,M43TODOUFUKEN B";
		$sql .= "        ,(";
		$sql .= "            SELECT";
		$sql .= "                    A2.M03_ENSEN_CD";
		$sql .= "                    ,A2.M03_TODOUFUKEN_CD";
		$sql .= "                    ,A2.M03_EKI_CD";
		$sql .= "                    ,A2.M03_EKI_NAME";
		$sql .= "                    ,SUM(A1.REC_CNT) AS EKI_REC_COUNT";
		$sql .= "                    ,NVL(A3.REC_CNT, 0) AS ENSEN_REC_COUNT";
		$sql .= "                FROM";
		$sql .= "                    (";
		$sql .= "                        SELECT";
		$sql .= "                                M03_EKI_CD AS T03_EKI_CD";
		$sql .= "                                ,REC_CNT";
		$sql .= "                            FROM";
		$sql .= "                                (";
		$sql .= "                                    SELECT";
		$sql .= "                                            M03_EKI_CD";
		$sql .= "                                            ,SUM(T63_COUNT) AS REC_CNT";
		$sql .= "                                        FROM";
		$sql .= "                                            M03EKI";
		$sql .= "                                            ,M05TENPO_INFO";
		$sql .= "                                            ,T63RENRAKU_EKI_SUM";
		$sql .= "                                        WHERE";
		$sql .= "                                            (";
		$sql .= "                                                M03_TODOUFUKEN_CD = '13'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '11'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '12'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '01'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '22'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '43'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '14'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '15'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '40'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '41'";
		$sql .= "                                            )";
		$sql .= "                                            AND (M03_ENSEN_CD = '2162')";
		$sql .= "                                            AND M03_RENRAKU_EKI_CD IS NOT NULL";
		$sql .= "                                            AND T63_TENPO_CD IS NOT NULL";
		$sql .= "                                            AND T63_RENRAKU_CD = M03_RENRAKU_EKI_CD";
		$sql .= "                                            AND T63_DATA_KUBUN = 0";
		$sql .= "                                            AND M05_TENPO_CD = T63_TENPO_CD";
		$sql .= "                                            AND (M05_HOUZIN_CD = '0411')";
		$sql .= "                                            AND (";
		$sql .= "                                                M05_OEM = 1";
		$sql .= "                                                OR M05_OEM = 3";
		$sql .= "                                            )";
		$sql .= "                                        GROUP BY";
		$sql .= "                                            M03_EKI_CD";
		$sql .= "                                    UNION ALL";
		$sql .= "                                    SELECT";
		$sql .= "                                            M03_EKI_CD";
		$sql .= "                                            ,COUNT(T03_HEYA_CD) AS REC_CNT";
		$sql .= "                                        FROM";
		$sql .= "                                            M03EKI";
		$sql .= "                                            ,M05TENPO_INFO";
		$sql .= "                                            ,T03WEB_HEYA";
		$sql .= "                                        WHERE";
		$sql .= "                                            (";
		$sql .= "                                                M03_TODOUFUKEN_CD = '13'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '11'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '12'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '01'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '22'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '43'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '14'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '15'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '40'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '41'";
		$sql .= "                                            )";
		$sql .= "                                            AND (M03_ENSEN_CD = '2162')";
		$sql .= "                                            AND (";
		$sql .= "                                                T03_TODOUFUKEN_CD = '13'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '11'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '12'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '01'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '22'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '43'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '14'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '15'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '40'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '41'";
		$sql .= "                                            )";
		$sql .= "                                            AND (T03_ENSEN_CD01 = '2162')";
		$sql .= "                                            AND T03_EKI_CD01 = M03_EKI_CD";
		$sql .= "                                            AND T03_RENRAKU_EKI_CD01 IS NULL";
		$sql .= "                                            AND M03_RENRAKU_EKI_CD IS NULL";
		$sql .= "                                            AND M05_TENPO_CD = T03_TENPO_CD";
		$sql .= "                                            AND (M05_HOUZIN_CD = '0411')";
		$sql .= "                                            AND (";
		$sql .= "                                                M05_OEM = 1";
		$sql .= "                                                OR M05_OEM = 3";
		$sql .= "                                            )";
		$sql .= "                                        GROUP BY";
		$sql .= "                                            M03_EKI_CD";
		$sql .= "                                    UNION ALL";
		$sql .= "                                    SELECT";
		$sql .= "                                            M03_EKI_CD";
		$sql .= "                                            ,COUNT(T03_HEYA_CD) AS REC_CNT";
		$sql .= "                                        FROM";
		$sql .= "                                            M03EKI";
		$sql .= "                                            ,M05TENPO_INFO";
		$sql .= "                                            ,T03WEB_HEYA";
		$sql .= "                                        WHERE";
		$sql .= "                                            (";
		$sql .= "                                                M03_TODOUFUKEN_CD = '13'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '11'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '12'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '01'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '22'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '43'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '14'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '15'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '40'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '41'";
		$sql .= "                                            )";
		$sql .= "                                            AND (M03_ENSEN_CD = '2162')";
		$sql .= "                                            AND (";
		$sql .= "                                                T03_TODOUFUKEN_CD = '13'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '11'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '12'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '01'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '22'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '43'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '14'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '15'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '40'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '41'";
		$sql .= "                                            )";
		$sql .= "                                            AND (T03_ENSEN_CD02 = '2162')";
		$sql .= "                                            AND T03_EKI_CD02 = M03_EKI_CD";
		$sql .= "                                            AND T03_RENRAKU_EKI_CD02 IS NULL";
		$sql .= "                                            AND M03_RENRAKU_EKI_CD IS NULL";
		$sql .= "                                            AND M05_TENPO_CD = T03_TENPO_CD";
		$sql .= "                                            AND (M05_HOUZIN_CD = '0411')";
		$sql .= "                                            AND (";
		$sql .= "                                                M05_OEM = 1";
		$sql .= "                                                OR M05_OEM = 3";
		$sql .= "                                            )";
		$sql .= "                                        GROUP BY";
		$sql .= "                                            M03_EKI_CD";
		$sql .= "                                    UNION ALL";
		$sql .= "                                    SELECT";
		$sql .= "                                            M03_EKI_CD";
		$sql .= "                                            ,COUNT(T03_HEYA_CD) AS REC_CNT";
		$sql .= "                                        FROM";
		$sql .= "                                            M03EKI";
		$sql .= "                                            ,M05TENPO_INFO";
		$sql .= "                                            ,T03WEB_HEYA";
		$sql .= "                                        WHERE";
		$sql .= "                                            (";
		$sql .= "                                                M03_TODOUFUKEN_CD = '13'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '11'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '12'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '01'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '22'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '43'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '14'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '15'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '40'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '41'";
		$sql .= "                                            )";
		$sql .= "                                            AND (M03_ENSEN_CD = '2162')";
		$sql .= "                                            AND (";
		$sql .= "                                                T03_TODOUFUKEN_CD = '13'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '11'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '12'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '01'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '22'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '43'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '14'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '15'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '40'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '41'";
		$sql .= "                                            )";
		$sql .= "                                            AND (T03_ENSEN_CD03 = '2162')";
		$sql .= "                                            AND T03_EKI_CD03 = M03_EKI_CD";
		$sql .= "                                            AND T03_RENRAKU_EKI_CD03 IS NULL";
		$sql .= "                                            AND M03_RENRAKU_EKI_CD IS NULL";
		$sql .= "                                            AND M05_TENPO_CD = T03_TENPO_CD";
		$sql .= "                                            AND (M05_HOUZIN_CD = '0411')";
		$sql .= "                                            AND (";
		$sql .= "                                                M05_OEM = 1";
		$sql .= "                                                OR M05_OEM = 3";
		$sql .= "                                            )";
		$sql .= "                                        GROUP BY";
		$sql .= "                                            M03_EKI_CD";
		$sql .= "                                )";
		$sql .= "                            GROUP BY";
		$sql .= "                                M03_EKI_CD";
		$sql .= "                                ,REC_CNT";
		$sql .= "                    ) A1";
		$sql .= "                    ,(";
		$sql .= "                        SELECT";
		$sql .= "                                M03_ENSEN_CD";
		$sql .= "                                ,M03_TODOUFUKEN_CD";
		$sql .= "                                ,M03_EKI_CD";
		$sql .= "                                ,nvl(M03_EKI_ALIAS,M03_EKI_NAME) M03_EKI_NAME";
		$sql .= "                            FROM";
		$sql .= "                                M03EKI";
		$sql .= "                            WHERE";
		$sql .= "                                (";
		$sql .= "                                    M03_TODOUFUKEN_CD = '13'";
		$sql .= "                                    OR M03_TODOUFUKEN_CD = '11'";
		$sql .= "                                    OR M03_TODOUFUKEN_CD = '12'";
		$sql .= "                                    OR M03_TODOUFUKEN_CD = '01'";
		$sql .= "                                    OR M03_TODOUFUKEN_CD = '22'";
		$sql .= "                                    OR M03_TODOUFUKEN_CD = '43'";
		$sql .= "                                    OR M03_TODOUFUKEN_CD = '14'";
		$sql .= "                                    OR M03_TODOUFUKEN_CD = '15'";
		$sql .= "                                    OR M03_TODOUFUKEN_CD = '40'";
		$sql .= "                                    OR M03_TODOUFUKEN_CD = '41'";
		$sql .= "                                )";
		$sql .= "                                AND (M03_ENSEN_CD = '2162')";
		$sql .= "                    ) A2";
		$sql .= "                    ,(";
		$sql .= "                        SELECT";
		$sql .= "                                M03_ENSEN_CD AS T03_ENSEN_CD";
		$sql .= "                                ,SUM(REC_CNT) AS REC_CNT";
		$sql .= "                            FROM";
		$sql .= "                                (";
		$sql .= "                                    SELECT";
		$sql .= "                                            M03_ENSEN_CD";
		$sql .= "                                            ,SUM(T63_COUNT) AS REC_CNT";
		$sql .= "                                        FROM";
		$sql .= "                                            M03EKI";
		$sql .= "                                            ,M05TENPO_INFO";
		$sql .= "                                            ,T63RENRAKU_EKI_SUM";
		$sql .= "                                        WHERE";
		$sql .= "                                            (";
		$sql .= "                                                M03_TODOUFUKEN_CD = '13'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '11'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '12'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '01'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '22'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '43'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '14'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '15'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '40'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '41'";
		$sql .= "                                            )";
		$sql .= "                                            AND (M03_ENSEN_CD = '2162')";
		$sql .= "                                            AND M03_RENRAKU_EKI_CD IS NOT NULL";
		$sql .= "                                            AND T63_TENPO_CD IS NOT NULL";
		$sql .= "                                            AND T63_RENRAKU_CD = M03_RENRAKU_EKI_CD";
		$sql .= "                                            AND T63_DATA_KUBUN = 0";
		$sql .= "                                            AND M05_TENPO_CD = T63_TENPO_CD";
		$sql .= "                                            AND (M05_HOUZIN_CD = '0411')";
		$sql .= "                                            AND (";
		$sql .= "                                                M05_OEM = 1";
		$sql .= "                                                OR M05_OEM = 3";
		$sql .= "                                            )";
		$sql .= "                                        GROUP BY";
		$sql .= "                                            M03_ENSEN_CD";
		$sql .= "                                    UNION ALL";
		$sql .= "                                    SELECT";
		$sql .= "                                            M03_ENSEN_CD";
		$sql .= "                                            ,COUNT(T03_HEYA_CD) AS REC_CNT";
		$sql .= "                                        FROM";
		$sql .= "                                            M03EKI";
		$sql .= "                                            ,M05TENPO_INFO";
		$sql .= "                                            ,T03WEB_HEYA";
		$sql .= "                                        WHERE";
		$sql .= "                                            (";
		$sql .= "                                                M03_TODOUFUKEN_CD = '13'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '11'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '12'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '01'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '22'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '43'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '14'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '15'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '40'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '41'";
		$sql .= "                                            )";
		$sql .= "                                            AND (M03_ENSEN_CD = '2162')";
		$sql .= "                                            AND (";
		$sql .= "                                                T03_TODOUFUKEN_CD = '13'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '11'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '12'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '01'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '22'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '43'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '14'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '15'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '40'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '41'";
		$sql .= "                                            )";
		$sql .= "                                            AND (T03_ENSEN_CD021 = '2162')";
		$sql .= "                                            AND T03_EKI_CD01 = M03_EKI_CD";
		$sql .= "                                            AND T03_RENRAKU_EKI_CD01 IS NULL";
		$sql .= "                                            AND M03_RENRAKU_EKI_CD IS NULL";
		$sql .= "                                            AND M05_TENPO_CD = T03_TENPO_CD";
		$sql .= "                                            AND (M05_HOUZIN_CD = '0411')";
		$sql .= "                                            AND (";
		$sql .= "                                                M05_OEM = 1";
		$sql .= "                                                OR M05_OEM = 3";
		$sql .= "                                            )";
		$sql .= "                                        GROUP BY";
		$sql .= "                                            M03_ENSEN_CD";
		$sql .= "                                    UNION ALL";
		$sql .= "                                    SELECT";
		$sql .= "                                            M03_ENSEN_CD";
		$sql .= "                                            ,COUNT(T03_HEYA_CD) AS REC_CNT";
		$sql .= "                                        FROM";
		$sql .= "                                            M03EKI";
		$sql .= "                                            ,M05TENPO_INFO";
		$sql .= "                                            ,T03WEB_HEYA";
		$sql .= "                                        WHERE";
		$sql .= "                                            (";
		$sql .= "                                                M03_TODOUFUKEN_CD = '13'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '11'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '12'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '01'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '22'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '43'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '14'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '15'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '40'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '41'";
		$sql .= "                                            )";
		$sql .= "                                            AND (M03_ENSEN_CD = '2162')";
		$sql .= "                                            AND (";
		$sql .= "                                                T03_TODOUFUKEN_CD = '13'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '11'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '12'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '01'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '22'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '43'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '14'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '15'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '40'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '41'";
		$sql .= "                                            )";
		$sql .= "                                            AND (T03_ENSEN_CD02 = '2162')";
		$sql .= "                                            AND T03_EKI_CD02 = M03_EKI_CD";
		$sql .= "                                            AND T03_RENRAKU_EKI_CD02 IS NULL";
		$sql .= "                                            AND M03_RENRAKU_EKI_CD IS NULL";
		$sql .= "                                            AND M05_TENPO_CD = T03_TENPO_CD";
		$sql .= "                                            AND (M05_HOUZIN_CD = '0411')";
		$sql .= "                                            AND (";
		$sql .= "                                                M05_OEM = 1";
		$sql .= "                                                OR M05_OEM = 3";
		$sql .= "                                            )";
		$sql .= "                                        GROUP BY";
		$sql .= "                                            M03_ENSEN_CD";
		$sql .= "                                    UNION ALL";
		$sql .= "                                    SELECT";
		$sql .= "                                            M03_ENSEN_CD";
		$sql .= "                                            ,COUNT(T03_HEYA_CD) AS REC_CNT";
		$sql .= "                                        FROM";
		$sql .= "                                            M03EKI";
		$sql .= "                                            ,M05TENPO_INFO";
		$sql .= "                                            ,T03WEB_HEYA";
		$sql .= "                                        WHERE";
		$sql .= "                                            (";
		$sql .= "                                                M03_TODOUFUKEN_CD = '13'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '11'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '12'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '01'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '22'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '43'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '14'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '15'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '40'";
		$sql .= "                                                OR M03_TODOUFUKEN_CD = '41'";
		$sql .= "                                            )";
		$sql .= "                                            AND (M03_ENSEN_CD = '2162')";
		$sql .= "                                            AND (";
		$sql .= "                                                T03_TODOUFUKEN_CD = '13'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '11'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '12'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '01'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '22'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '43'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '14'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '15'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '40'";
		$sql .= "                                                OR T03_TODOUFUKEN_CD = '41'";
		$sql .= "                                            )";
		$sql .= "                                            AND (T03_ENSEN_CD03 = '2162')";
		$sql .= "                                            AND T03_EKI_CD03 = M03_EKI_CD";
		$sql .= "                                            AND T03_RENRAKU_EKI_CD03 IS NULL";
		$sql .= "                                            AND M03_RENRAKU_EKI_CD IS NULL";
		$sql .= "                                            AND M05_TENPO_CD = T03_TENPO_CD";
		$sql .= "                                            AND (M05_HOUZIN_CD = '0411')";
		$sql .= "                                            AND (";
		$sql .= "                                                M05_OEM = 1";
		$sql .= "                                                OR M05_OEM = 3";
		$sql .= "                                            )";
		$sql .= "                                        GROUP BY";
		$sql .= "                                            M03_ENSEN_CD";
		$sql .= "                                )";
		$sql .= "                            GROUP BY";
		$sql .= "                                M03_ENSEN_CD";
		$sql .= "                    ) A3";
		$sql .= "                WHERE";
		$sql .= "                    A1.T03_EKI_CD(+) = A2.M03_EKI_CD";
		$sql .= "                    AND A2.M03_ENSEN_CD = A3.T03_ENSEN_CD";
		$sql .= "                GROUP BY";
		$sql .= "                    A2.M03_ENSEN_CD";
		$sql .= "                    ,A2.M03_TODOUFUKEN_CD";
		$sql .= "                    ,A2.M03_EKI_CD";
		$sql .= "                    ,A2.M03_EKI_NAME";
		$sql .= "                    ,A3.REC_CNT";
		$sql .= "        ) T";
		$sql .= "    WHERE";
		$sql .= "        T.M03_ENSEN_CD = A.M02_ENSEN_CD";
		$sql .= "        AND T.M03_TODOUFUKEN_CD = B.M43_TODOUFUKEN_CD";
		$sql .= "    ORDER BY";
		$sql .= "        A.M02_ENSEN_KANA ASC";
		$sql .= "        ,T.M03_EKI_CD ASC";

		return $sql;
	}

	/**
	* 駅名データ検索用SQL文の取得(物件リクエスト)
	*
	* 駅名一覧データ検索用SQL文の取得を行う(物件リクエスト)
	* @access	public
	* @param	array
	* @param	array
	* @return
	*/
	public function generateRequestSql($params,$db_params)
	{
		$sql = "SELECT";
		$sql .= "        T1.M03_EKI_CD AS SORT";
		$sql .= "        ,T1.M02_ENSEN_CD AS ENSEN_CD";
		$sql .= "        ,T1.M03_EKI_CD AS EKI_CD";
		$sql .= "        ,to_single_byte(T1.M02_ENSEN_NAME) AS ENSEN_NAME";
		$sql .= "        ,to_single_byte(T1.M03_EKI_NAME) AS EKI_NAME";
		$sql .= "    FROM";
		$sql .= "        (";
		$sql .= "            SELECT";
		$sql .= "                    M03_TODOUFUKEN_CD";
		$sql .= "                    ,M03_TODOUFUKEN";
		$sql .= "                    ,M02_ENSEN_NAME";
		$sql .= "                    ,M02_ENSEN_CD";
		$sql .= "                    ,M03_EKI_CD";
		$sql .= "                    ,CASE";
		$sql .= "                        WHEN M03_EKI_NAME = '＊＊＊' THEN M03_TODOUFUKEN || M02_ENSEN_NAME";
		$sql .= "                        ELSE M03_EKI_NAME";
		$sql .= "                    END AS M03_EKI_NAME";
		$sql .= "                FROM";
		$sql .= "                    (";
		$sql .= "                        SELECT";
		$sql .= "                                M03_TODOUFUKEN_CD";
		$sql .= "                                ,M03_TODOUFUKEN";
		$sql .= "                                ,M03_ENSEN_CD";
		$sql .= "                                ,M03_ENSEN_NAME";
		$sql .= "                                ,M03_EKI_CD";
		$sql .= "                                ,nvl(M03_EKI_ALIAS,M03_EKI_NAME) M03_EKI_NAME";
		$sql .= "                            FROM";
		$sql .= "                                M03EKI";
		$sql .= "                            WHERE";
		$sql .= "                                (M03_ENSEN_CD = '2198')";
		$sql .= "                                AND (M03_TODOUFUKEN_CD = '13')";
		$sql .= "                    ) M03";
		$sql .= "                    ,(";
		$sql .= "                        SELECT";
		$sql .= "                                M02_ENSEN_CD";
		$sql .= "                                ,M02_ENSEN_NAME";
		$sql .= "                            FROM";
		$sql .= "                                M02ENSEN";
		$sql .= "                    ) M02";
		$sql .= "                WHERE";
		$sql .= "                    M02_ENSEN_CD = M03_ENSEN_CD";
		$sql .= "        ) T1";
		$sql .= "    GROUP BY";
		$sql .= "        T1.M03_TODOUFUKEN_CD";
		$sql .= "        ,T1.M02_ENSEN_NAME";
		$sql .= "        ,T1.M02_ENSEN_CD";
		$sql .= "        ,T1.M03_EKI_CD";
		$sql .= "        ,T1.M03_EKI_NAME";
		$sql .= "    ORDER BY";
		$sql .= "        ENSEN_CD ASC";
		$sql .= "        ,SORT ASC";

		return $sql;
    }

	/**
	* 沿線CDから都道府県を取得する
	*
	* @access	public
	* @param	array
	* @param	array
	* @return   string  $sql  生成SQL
	*/
	public function generateMaxRailCntSql($params,&$db_params)
	{
		//バインド変数のセット
		// 沿線CD
		$db_params['railCd'] = $params['RailCd'][0];
		//  データ区分
		if(!empty($params['SrhKbn']) && $params['SrhKbn'] == Apm_Config_Search::SRHKBN_SYATAKU){
			$db_params['dataKubun'] = 2;
		}else{
			$db_params['dataKubun'] = 0;
		}		

		$sql  = " SELECT ";
		$sql .= "        T57_TODOUFUKEN_CD AS M04_TODOUFUKEN_CD";
		$sql .= "       ,T57_ENSEN_CD AS M02_ENSEN_CD";
		$sql .= "       ,T57_ENSEN_CNT AS T57_ENSEN_SHIKUCHOUSON_CNT";
		$sql .= "   FROM";
		$sql .= "       T57ENSEN_SUM";
		$sql .= "  WHERE";
		$sql .= "        T57_ENSEN_CD = :railCd ";
		$sql .= " AND T57_DATA_KUBUN(+) = :dataKubun ";
		$sql .= "  ORDER BY ";
		$sql .= "        T57_ENSEN_CNT DESC";
		$sql .= "       ,T57_TODOUFUKEN_CD ASC";
		
		return $sql;
    }

	/**
	* 都道府県ごとに沿線集計値を取得する
	*
	* @access	public
	* @param	array
	* @param	array
	* @return   string  $sql  生成SQL
	*/
	public function generatePrefCdByStCdSql($params,&$db_params)
	{

		$sepa   = "'";
		$conmma = "";

		foreach($params as $key => $val){
			$db_params['stCd_' . $key] = $val;
		}

		$sql  = "SELECT ";
		$sql .= "        M03_EKI_CD";
		$sql .= "       ,M03_TODOUFUKEN_CD";
		$sql .= "    FROM";
		$sql .= "        M03EKI";
		$sql .= "    WHERE";
		$sql .= "        M03_EKI_CD IN ( ";
		foreach($db_params as $key => $val){
			$sql .= $conmma . ':' . $key ;
			$conmma = ",";
		}
		$sql .= " ) ";

		return $sql;
    }

   /**
     * 駅名取得用SQL文の取得
     *
     * 駅名用SQL文の取得を行う
     * @access	public
     * @param	array
     * @param	array
     * @return	array 駅名取得用SQL
     */
    public function generateStNameByStCdSql($params, &$db_params)
    {

    	foreach($params['StCd'] as $key => $val){
    		$db_params['stCd' . $key] = $val;
    	}

    	$sql = "";
		$sql .= "SELECT ";
		$sql .= "    distinct M03_EKI_CD ";
		$sql .= "    ,M03_TODOUFUKEN_CD ";
		$sql .= "    ,CASE";
		$sql .= "        WHEN M03_EKI_NAME = '＊＊＊' THEN M43_TODOUFUKEN || to_single_byte(M03_ENSEN_NAME) ";
		$sql .= "     ELSE to_single_byte(M03_EKI_NAME) ";
		$sql .= "     END AS M03_EKI_NAME ";
		$sql .= "    ,M03_EKI_ALIAS as M03_EKI_ALIAS ";
		$sql .= "FROM ";
		$sql .= "    M03EKI ";
		$sql .= "   ,M43TODOUFUKEN ";
		$sql .= "WHERE ";
		$sql .= "        M03_EKI_CD IN ( ";
		$sepa = "";
		foreach($params['StCd'] as $key => $val){
			$sql .= $sepa . " :stCd" . $key;
			$sepa = ",";
		}
		$sql .= "        ) ";
		$sql .= "  AND M03_TODOUFUKEN_CD = M43_TODOUFUKEN_CD ";
		$sql .= "ORDER BY ";
		$sql .= "        M03_EKI_CD ";

        return $sql;
    }

    /*
     * 人気のエリアから探す
     * X件
     *
     */
    public function getNinkiShikuchousonData($params){
         
        $db_params = array();
         
        //  データ区分
        $db_params['dataKubun'];
        if(!empty($params['shikireizero']) && $params['shikireizero'] == "on"){
            $db_params['dataKubun'] = 1;
        }else if(!empty($params['shikikin_nashi']) && $params['shikikin_nashi'] == "on" &&
            (!empty($params['reikin_nashi']) && $params['reikin_nashi'] == "on")){
            $db_params['dataKubun'] = 3;
        }else if(!empty($params['shikikin_nashi']) && $params['shikikin_nashi'] == "on"){
            $db_params['dataKubun'] = 4;
        }else if(!empty($params['reikin_nashi']) && $params['reikin_nashi'] == "on"){
            $db_params['dataKubun'] = 5;
        }else if(!empty($params['SrhKbn']) && $params['SrhKbn'] == Apm_Config_Search::SRHKBN_SYATAKU){
            $db_params['dataKubun'] = 2;
        }else{
            $db_params['dataKubun'] = 0;
        }        
        
        $sql= "SELECT T54_TODOUFUKEN_CD AS TODOUFUKEN_CD, T54_ENSEN_CD AS ENSEN_CD, T54_EKI_CD AS EKI_CD, T54_EKI_NAME AS EKI_NAME ";
        $sql .= "   FROM T54EKI_SUM";
        $sql .= "   WHERE T54_EKI_CNT > 0 AND T54_DATA_KUBUN =  :dataKubun";  
        //都道府県ごとの人気エリア
        if(isset($params['PrefCd']) && $params['PrefCd'] != ''){
            $sql .= " AND T57_TODOUFUKEN_CD = '".$params['PrefCd']."'";
        }      
        $sql .= " ORDER BY DBMS_RANDOM.RANDOM ";
    
        $sql = " SELECT * FROM ( " . $sql . " ) WHERE ROWNUM <= ".$params['listCount']; //トップｎ件   
        $var = $this->dbGetList($sql, $db_params);
         
        return $var;
    }
    
    /*
     * 近隣駅検索
     */
    function getNearEki($ensenCd, $ekiCd){
        $sql = "
            SELECT * FROM(
            	SELECT * FROM (
            		SELECT M03_TODOUFUKEN_CD AS TODOUFUKEN_CD, M03_ENSEN_NAME AS ENSEN_NAME, M03_EKI_CD AS EKI_CD, M03_EKI_NAME AS EKI_NAME 
            		FROM M03EKI where  M03_ENSEN_CD = :ensenCd AND M03_EKI_CD > :ekiCd ORDER BY M03_EKI_CD
            	) WHERE rownum < 3
            	UNION
            	(SELECT M03_TODOUFUKEN_CD AS TODOUFUKEN_CD, M03_ENSEN_NAME AS ENSEN_NAME, M03_EKI_CD AS EKI_CD, M03_EKI_NAME AS EKI_NAME 
            		FROM M03EKI where M03_ENSEN_CD = :ensenCd AND M03_EKI_CD = :ekiCd)
            	UNION
            	SELECT * FROM (
            		SELECT M03_TODOUFUKEN_CD AS TODOUFUKEN_CD, M03_ENSEN_NAME AS ENSEN_NAME, M03_EKI_CD AS EKI_CD, M03_EKI_NAME AS EKI_NAME 
            		FROM M03EKI where M03_ENSEN_CD = :ensenCd AND M03_EKI_CD < :ekiCd ORDER BY M03_EKI_CD DESC
            	) WHERE rownum < 3
            
            ) ORDER BY EKI_CD";
                        
        
        $db_params = array();
        $db_params['ensenCd'] = $ensenCd;
        $db_params['ekiCd'] = $ekiCd;
        return $this->dbGetList($sql, $db_params);        
    }
    
    /*
     * 都道府県のすべて駅
     */
    function getPrefEki($prefCd){
        $sql = "SELECT * FROM (
                	SELECT M03_EKI_CD AS EKI_CD, M03_ENSEN_NAME AS ENSEN_NAME
                		,(CASE WHEN M03_EKI_ALIAS IS NOT NULL THEN M03_EKI_ALIAS ELSE M03_EKI_NAME END) AS EKI_NAME
                	FROM M03EKI WHERE M03_TODOUFUKEN_CD =:prefCd ORDER BY DBMS_RANDOM.RANDOM
                ) WHERE ROWNUM <= 30
            ";
        $db_params = array();
        $db_params['prefCd'] = $prefCd;
        return $this->dbGetList($sql, $db_params);
    }
    // 20141220 S_Add
    /**
     * エリア検索（左パネル）のキーワードから、駅を取得
     * @param unknown_type $params
     */
    public function getSearchEki($params)
    {
        $sql  = "";
        $sql .= "SELECT";
        $sql .= "       M03_ENSEN_CD ";
        $sql .= "      ,M03_EKI_CD ";
        $sql .= "      ,M03_ENSEN_NAME ";
        $sql .= "      ,M03_ENSEN_RYAKU ";
        $sql .= "      ,M03_EKI_NAME ";
        $sql .= "      ,M03_EKI_RYAKU ";
        $sql .= "      ,M03_RENRAKU_ENSEN_CD ";
        $sql .= "      ,M03_AS_ENSEN_CD ";
        $sql .= "      ,M03_AS_EKI_CD ";
        $sql .= "      ,M03_TODOUFUKEN_CD ";
        $sql .= "      ,M03_TODOUFUKEN ";
        $sql .= "      ,M03_AS_ENSEN_NAME ";
        $sql .= "      ,M03_AS_EKI_NAME ";
        $sql .= "      ,M03_RENRAKU_EKI_CD ";
        $sql .= "      ,M03_ROSENZU_EKI_CD ";
        $sql .= "      ,M03_IDO ";
        $sql .= "      ,M03_KEIDO ";
        $sql .= "      ,M03_EKI_ALIAS ";
        $sql .= "      ,M03_EXPRESS_KBN ";
        $sql .= "  FROM";
        $sql .= "       M03EKI";
        $sql .= " WHERE";
        $sql .= "       M03_ENSEN_CD = ";
        $sql .= "'" . $params['prefcd'] . "' ";
        $sql .= " ORDER BY";
        $sql .= "       M03_EKI_CD ";
        

        return $this->dbGetList($sql, $db_params);
    }
    // 20141220 E_Add
}
?>